<?php

class Run_Tick
{
	static public  $ticks=array();
	public static function pick($name)
	{
		list($usec, $sec) = explode(' ', microtime());
		$t = (int)(($usec+($sec%1000))*1000);
		$tick['name']=$name;
		$tick['time']=$t;
		self::$ticks[]=$tick;
	}
	public static function dump()
	{
		$last_tick=null;
		$text='';
		foreach (self::$ticks as $key => $value)
		{
			$text.=$value['name'].'='.$value['time'];
			if(isset($last_tick))
			{
				$text.=',use='.($value['time']-$last_tick['time']);
			}
			$text.="\r\n";
			$last_tick = $value;
		}
		return $text;		
	}
	
	
	public static function dumplast()
	{
		$count = count(self::$ticks);
		if($count<2)
		{
			return ;
		}
		$last = self::$ticks[$count-2];
		$end = self::$ticks[$count-1];
		$text =$last['name'].'->'.$end['name'].'use '.($end['time']-$last['time']);
	}
}
if($argv)
{
	if($argv[1]=='ut_runtick')
	{
		echo runtick::dump()."\r\n";
	}
}
?>